package com.xiaowan.login.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("login")
public class LoginController {
    /**
     *@Author xiaowan
     *@Date 2017/12/5 0005 23:18
     *@Description 登录方法
     */
    @RequestMapping("/check")
    @ResponseBody
    public String checkLogin(HttpServletRequest request){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        UsernamePasswordToken token = new UsernamePasswordToken(username,password);
        Subject subject = SecurityUtils.getSubject();
        try{
            subject.login(token);
            SecurityUtils.getSubject().getSession().setTimeout(1800000);
        }catch(Exception e){
            return "login_fail";
        }
        return "login_succ";

    }
}
